import java.util.Scanner;

/**
 * File: AccountHolderTest.java
 * @author Zhiqiang Zhu
 *  Test program for class AccountHolder Enter a balance and
 *  use it to construct an new AccountHolder object. Ask the user to
 *  deposit and withdraw once and then calculate the balance using the
 *  annual interest rate and display it.
 */
public class AccountHolderTest {

	public static void main(String[] args) {
		// Request user to enter initial balance
		Scanner sc = new Scanner(System.in);

		// a double variable used to store user input
		double doubleValue = 0;

		// Request user to enter initial balance
		do {
			System.out.print("Please enter your initial balance:");
			doubleValue = sc.nextDouble();

			if (doubleValue < 0) {
				System.out.println("ERROR! Only positive values are allowed.");
			}
		} while (doubleValue < 0);

		// Create account and set initial balance
		AccountHolder ah001 = new AccountHolder(doubleValue);

		// Set interest rate
		AccountHolder.annualInterestRate = 0.04;
		System.out.printf("The current annual interest rate is:%.2f%%\n", AccountHolder.annualInterestRate);

		// Show menu
		int choice = 0;
		do {
			System.out.println();
			System.out.println("Please enter your select:");
			System.out.println("1 - Deposit");
			System.out.println("2 - Withdraw");
			System.out.println("3 - Print balance");
			System.out.println("0 - Exit");

			choice = sc.nextInt();

			switch (choice) {
			case 1: {
				// Get a deposit
				System.out.println();
				System.out.print("Please enter a deposit:");
				doubleValue = sc.nextDouble();

				ah001.deposit(doubleValue);
				break;
			}
			case 2: {
				// Get a withdraw
				System.out.println();
				System.out.print("Please enter a withdraw:");
				doubleValue = sc.nextDouble();

				if (!ah001.withdraw(doubleValue)) {
					System.out.println("You can't withdraw this amount because the balance cannot go below $50.");
				}
				break;
			}
			case 3: {
				// Update monthly Interest to balance
				ah001.monthlyInterest();

				System.out.println();
				System.out.printf("Current balance = $%.2f", ah001.getBalance());
				System.out.println();
				break;
			}
			}	// switch
		} while (choice > 0);
		System.out.println("Good bye!");
	}

}
